﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Vara_Data_Layer.Vara_Data_Asset;

namespace AssetTracking.User_Controls.Asset_Module
{
    public partial class Asset_Modal : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        public void Show(int AssetId)
        {
            //if the asset ID is greater than 0 then return that asset, else insert an asset and return the empty details for that
            if (AssetId > 0)
            {
                Zentrix_Modal_cc1.Show();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "LoadScripts", "window.onLoad = function () { onLoadChecks(); };", true);
                Vara_Data_IAsset AssetDetails = new Vara_Data_Asset_Controller().ReturnAsset(AssetId);
                LoadInterfaces(AssetDetails);
            }
            else
            {
                Zentrix_Modal_cc1.Show();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "LoadScripts", "window.onLoad = function () { onLoadChecks(); };", true);
                Vara_Data_IAsset NewAsset = new Vara_Data_Asset();
                Vara_Data_Asset_Controller AssetController = new Vara_Data_Asset_Controller();
                AssetController.InsertAsset(NewAsset);                               
                LoadInterfaces(NewAsset);
            }
        }
        protected void LoadInterfaces(Vara_Data_IAsset AssetDetails)
        {
            Tab_1_Details1.Load_Interface(AssetDetails);
            Tab_2_Categories1.Load_Interface(AssetDetails);
            Tab_3_Purchase_Details1.Load_Interface(AssetDetails);
            Tab_4_Owner_Location1.Load_Interface(AssetDetails);
            Tab_5_Maintenance1.Load_Interface(AssetDetails);
            Tab_6_Additional1.Load_Interface(AssetDetails);
        }
        protected void ButtonClose_Click(object sender, EventArgs e)
        { 
            Zentrix_Modal_cc1.Hide();
            //Vara_Data_IAsset AssetCurrentlyLoaded = Tab_1_Details1.ReturnAssetCurrentlyLoaded();
            //Vara_Data_Asset_Controller AssetController = new Vara_Data_Asset_Controller();
            //AssetController.UpdateAsset(AssetCurrentlyLoaded);
        }
    }
}